\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{stb-math}[2019/03/16]

% --- Upright/normal d (for derivatives and integrals) ---
\newcommand*{\@dd}{\symnormal{d}}
\newcommand*{\pd}{\symnormal{\partial}}
\DeclareOption{normald}{
    \renewcommand*{\@dd}{\symnormal{d}}
    \renewcommand*{\pd}{\symnormal{\partial}}
}
\DeclareOption{uprightd}{
    \renewcommand*{\@dd}{\symup{d}}
    \renewcommand*{\pd}{\symup{\partial}}
}

% --- Re/Im or fraktur R and I (real part and imaginary part functions) ---
\newif\if@plainpart
\@plainparttrue

\DeclareOption{normalReIm}{\@plainparttrue}
\DeclareOption{frakturReIm}{\@plainpartfalse}

% --- Pass options to stb-brackets ---
\DeclareOption{setbar}{
    \PassOptionsToPackage{\CurrentOption}{stb-brackets}
}
\DeclareOption{setcolon}{
    \PassOptionsToPackage{\CurrentOption}{stb-brackets}
}
\DeclareOption{evalbar}{
    \PassOptionsToPackage{\CurrentOption}{stb-brackets}
}
\DeclareOption{evalbrackets}{
    \PassOptionsToPackage{\CurrentOption}{stb-brackets}
}

\ProcessOptions\relax

\RequirePackage{stb-brackets} % Loaded after options are passed
\RequirePackage{etoolbox}
\RequirePackage[math-style=ISO, bold-style=ISO]{unicode-math} % Allow typing unicode characters in math mode

\allowdisplaybreaks

% --- Macro for display math immediately following \item ---
\newif\if@nomathskip
\@nomathskipfalse
\newcommand*{\nomathskip}{\@nomathskiptrue}

\newcommand*{\add@noskiphooks}[1]{
    \BeforeBeginEnvironment{#1}{
        \if@nomathskip
            \setlength{\abovedisplayskip}{0em}
            \leavevmode
            \vspace*{-\baselineskip}
        \fi
    }
    \AfterEndEnvironment{#1}{\@nomathskipfalse}
}
\add@noskiphooks{align}
\add@noskiphooks{align*}
\add@noskiphooks{alignat}
\add@noskiphooks{alignat*}
\add@noskiphooks{equation}
\add@noskiphooks{equation*}
\add@noskiphooks{gather}
\add@noskiphooks{gather*}
\add@noskiphooks{multline}
\add@noskiphooks{multline*}

% --- Intervals ---
\DeclarePairedDelimiterX{\openint}[2]{\lparen}{\rparen}{#1, #2}
\DeclarePairedDelimiterX{\closedint}[2]{\lbrack}{\rbrack}{#1, #2}
\DeclarePairedDelimiterX{\openclosedint}[2]{\lparen}{\rbrack}{#1, #2}
\DeclarePairedDelimiterX{\closedopenint}[2]{\lbrack}{\rparen}{#1, #2}

% --- Group presentations ---
\DeclarePairedDelimiterX{\gppres}[2]{\langle}{\rangle}{#1 \delimsize\mid \mathopen{} #2}

% --- Operators ---
\DeclareMathOperator{\Arg}{Arg}
\DeclareMathOperator{\Aut}{Aut}
\DeclareMathOperator{\cis}{cis}
\DeclareMathOperator{\chr}{char} % \char is a Plain TeX command
\DeclareMathOperator{\Ext}{Ext}
\DeclareMathOperator{\Gal}{Gal}
\DeclareMathOperator{\GL}{GL}
\DeclareMathOperator{\Hom}{Hom}
\DeclareMathOperator{\id}{id}
\DeclareMathOperator{\im}{im}
\DeclareMathOperator{\lcm}{lcm}
\DeclareMathOperator{\Log}{Log}
\DeclareMathOperator{\PGL}{PGL}
\DeclareMathOperator{\PSL}{PSL}
\DeclareMathOperator{\Res}{Res}
\DeclareMathOperator{\res}{res}
\DeclareMathOperator{\sgn}{sgn}
\DeclareMathOperator{\SL}{SL}
\DeclareMathOperator{\Sym}{Sym}
\DeclareMathOperator{\Tor}{Tor}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\Tr}{Tr}
\DeclareMathOperator{\wt}{wt}

\if@plainpart
    \AtBeginDocument{
        \undef\Im
        \undef\Re
        \DeclareMathOperator{\Im}{Im}
        \DeclareMathOperator{\Re}{Re}
    }
\fi

% --- Multichoose ---
% Adapted from code by Paul Goborit: https://tex.stackexchange.com/a/5825
\newcommand{\multibinom}[2]{\left( \kern-0.20em \left( \genfrac{}{}{0pt}{}{#1}{#2} \right) \kern-0.20em \right)}

% --- Other binom-like notation ---
\newcommand*{\bracketsbinom}[2]{\genfrac{\lbrack}{\rbrack}{0pt}{}{#1}{#2}}
\newcommand*{\bracessbinom}[2]{\genfrac{\lbrack}{\rbrack}{0pt}{}{#1}{#2}}

% --- Symbols ---
% Number theory symbols
\newcommand*{\divides}{\mid}
\newcommand*{\ndivides}{\nmid}
\newcommand*{\nequiv}{\not\equiv}

% Normal subgroups
\newcommand*{\normalsub}{\vartriangleleft}
\newcommand*{\normalsubeq}{\trianglelefteq}
\newcommand*{\normalsup}{\vartriangleright}
\newcommand*{\normalsupeq}{\trianglerighteq}

% Arrows for injections, surjections, and bijections
\newcommand*{\injto}{\hookrightarrow}
\newcommand*{\injgets}{\hookleftarrow}
\newcommand*{\surjto}{\twoheadrightarrow}
\newcommand*{\surjgets}{\twoheadleftarrow}
\newcommand*{\bijto}{\similarrightarrow}
\newcommand*{\bijgets}{\similarleftarrow}

% --- Space for use after quantifiers ---
\newcommand*{\st}{\ }

% --- Derivatives ---
\NewDocumentCommand{\dd}{s}{\IfBooleanT{#1}{\mathop{}}\@dd}

\newcommand*{\deriv}[3][]{\frac{\dd^{#1} #2}{{\dd #3}^{#1}}}
\newcommand*{\pderiv}[3][]{\frac{\pd^{#1} #2}{{\pd #3}^{#1}}}

% --- Miscellaneous shortcuts ---
\newcommand*{\cycgp}[1]{\ZZ / #1 \ZZ}
\newcommand*{\mat}[1]{\begin{bmatrix} #1 \end{bmatrix}}
\newcommand*{\ol}[1]{\overline{#1}}

\newcommand*{\pfimplies}[2]{(\(#1 \implies #2\))}
\newcommand*{\pfimpliedby}[2]{(\(#1 \impliedby #2\))}
\newcommand*{\pfsubset}[2]{(\(#1 \subseteq #2\))}
\newcommand*{\pfsupset}[2]{(\(#1 \supseteq #2\))}

% --- Blackboard bold letters ---
\newcommand*{\bbA}{\symbb{A}}
\newcommand*{\bbB}{\symbb{B}}
\newcommand*{\bbC}{\symbb{C}}
\newcommand*{\bbD}{\symbb{D}}
\newcommand*{\bbE}{\symbb{E}}
\newcommand*{\bbF}{\symbb{F}}
\newcommand*{\bbG}{\symbb{G}}
\newcommand*{\bbH}{\symbb{H}}
\newcommand*{\bbI}{\symbb{I}}
\newcommand*{\bbJ}{\symbb{J}}
\newcommand*{\bbK}{\symbb{K}}
\newcommand*{\bbL}{\symbb{L}}
\newcommand*{\bbM}{\symbb{M}}
\newcommand*{\bbN}{\symbb{N}}
\newcommand*{\bbO}{\symbb{O}}
\newcommand*{\bbP}{\symbb{P}}
\newcommand*{\bbQ}{\symbb{Q}}
\newcommand*{\bbR}{\symbb{R}}
\newcommand*{\bbS}{\symbb{S}}
\newcommand*{\bbT}{\symbb{T}}
\newcommand*{\bbU}{\symbb{U}}
\newcommand*{\bbV}{\symbb{V}}
\newcommand*{\bbW}{\symbb{W}}
\newcommand*{\bbX}{\symbb{X}}
\newcommand*{\bbY}{\symbb{Y}}
\newcommand*{\bbZ}{\symbb{Z}}

% --- Calligraphic letters ---
\newcommand*{\calA}{\symcal{A}}
\newcommand*{\calB}{\symcal{B}}
\newcommand*{\calC}{\symcal{C}}
\newcommand*{\calD}{\symcal{D}}
\newcommand*{\calE}{\symcal{E}}
\newcommand*{\calF}{\symcal{F}}
\newcommand*{\calG}{\symcal{G}}
\newcommand*{\calH}{\symcal{H}}
\newcommand*{\calI}{\symcal{I}}
\newcommand*{\calJ}{\symcal{J}}
\newcommand*{\calK}{\symcal{K}}
\newcommand*{\calL}{\symcal{L}}
\newcommand*{\calM}{\symcal{M}}
\newcommand*{\calN}{\symcal{N}}
\newcommand*{\calO}{\symcal{O}}
\newcommand*{\calP}{\symcal{P}}
\newcommand*{\calQ}{\symcal{Q}}
\newcommand*{\calR}{\symcal{R}}
\newcommand*{\calS}{\symcal{S}}
\newcommand*{\calT}{\symcal{T}}
\newcommand*{\calU}{\symcal{U}}
\newcommand*{\calV}{\symcal{V}}
\newcommand*{\calW}{\symcal{W}}
\newcommand*{\calX}{\symcal{X}}
\newcommand*{\calY}{\symcal{Y}}
\newcommand*{\calZ}{\symcal{Z}}

% --- Script letters ---
\newcommand*{\scrA}{\symscr{A}}
\newcommand*{\scrB}{\symscr{B}}
\newcommand*{\scrC}{\symscr{C}}
\newcommand*{\scrD}{\symscr{D}}
\newcommand*{\scrE}{\symscr{E}}
\newcommand*{\scrF}{\symscr{F}}
\newcommand*{\scrG}{\symscr{G}}
\newcommand*{\scrH}{\symscr{H}}
\newcommand*{\scrI}{\symscr{I}}
\newcommand*{\scrJ}{\symscr{J}}
\newcommand*{\scrK}{\symscr{K}}
\newcommand*{\scrL}{\symscr{L}}
\newcommand*{\scrM}{\symscr{M}}
\newcommand*{\scrN}{\symscr{N}}
\newcommand*{\scrO}{\symscr{O}}
\newcommand*{\scrP}{\symscr{P}}
\newcommand*{\scrQ}{\symscr{Q}}
\newcommand*{\scrR}{\symscr{R}}
\newcommand*{\scrS}{\symscr{S}}
\newcommand*{\scrT}{\symscr{T}}
\newcommand*{\scrU}{\symscr{U}}
\newcommand*{\scrV}{\symscr{V}}
\newcommand*{\scrW}{\symscr{W}}
\newcommand*{\scrX}{\symscr{X}}
\newcommand*{\scrY}{\symscr{Y}}
\newcommand*{\scrZ}{\symscr{Z}}

\endinput